package drds.binlog.parse.index;

import com.google.common.collect.MapMaker;
import drds.binlog.common.position.LogPosition;
import drds.binlog.parse.exception.BinlogParseException;

import java.util.Map;
import java.util.Set;


public class MemoryLogPositionManager extends AbstractLogPositionManager
{

    private Map<String, LogPosition> positions;

    @Override
    public void start()
    {
        super.start();
        positions = new MapMaker().makeMap();
    }

    @Override
    public void stop()
    {
        super.stop();
        positions.clear();
    }

    @Override
    public LogPosition getLatestIndexBy(String destination)
    {
        return positions.get(destination);
    }

    @Override
    public void persistLogPosition(String destination, LogPosition logPosition) throws BinlogParseException
    {
        positions.put(destination, logPosition);
    }

    public Set<String> destinations()
    {
        return positions.keySet();
    }

}
